package fhjoanneum.itm11.antesk.simplehack;

import java.awt.GridLayout;
import java.awt.event.*;
import javax.swing.*;

public class GraphicWindow implements ActionListener
{
	private String title;
	private JFrame frame;
	private JMenuItem exit;
	private JMenuItem newgame;
	
	GraphicWindow(String title)
	{
		this.title = title;
	}
	
	public void makeFrame()
	{
		// Frame and panel
		frame = new JFrame(title);
		JPanel panel = new JPanel(new GridLayout());
		
				
		frame.add(panel);
		frame.setSize(800,600);
		frame.setResizable(false);
		
		// determines screen sizes and divides it by 2
		// centers the frame in the middle
		frame.setLocationRelativeTo(null);
		
		frame.setVisible(true);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// Menu bar
		JMenuBar menubar = new JMenuBar();
		frame.setJMenuBar(menubar);
		
		// Menu bar entries
		JMenu game = new JMenu("Game");
		JMenu settings = new JMenu("Settings");
		JMenu about = new JMenu("About");
		
		menubar.add(game);
		menubar.add(settings);
		menubar.add(about);
		
		// Game menu items
		newgame = new JMenuItem("New Game");
		JMenuItem loadgame = new JMenuItem("Load Game");
		JMenuItem savegame = new JMenuItem("Save Game");
		exit = new JMenuItem("Exit");
		
		game.add(newgame);
		game.add(loadgame);
		game.add(savegame);
		game.add(exit);
		
		// Adding of ActionListeners
		exit.addActionListener(this);

	}
	
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource().equals(exit))
		{
			int question = JOptionPane.showConfirmDialog(
					frame, 
					"Are you sure that you want to quit without saving?", 
					"Confirmation", 
					JOptionPane.YES_NO_OPTION);
			
			if(question == 0)
			{
				System.exit(0);
			}
		}
		
	}
	
	
}
